package com.mc.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
 
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public class TraderCenterUtil {
	private static TraderCenterUtil traderCenterUtil = new TraderCenterUtil();

	private TraderCenterUtil() {
	}

	public static TraderCenterUtil getInstance() {
		return traderCenterUtil;
	}

	public <T> String ParseListToJSON(List<T> list) {
		String result = "";
		ObjectMapper objectMapper = null;
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		if (list != null) {
			try {
				objectMapper = new ObjectMapper();
				objectMapper.writeValue(baos, list);

			} catch (JsonGenerationException e) {

				e.printStackTrace();
			} catch (JsonMappingException e) {

				e.printStackTrace();
			} catch (IOException e) {

				e.printStackTrace();
			}
		}
		result = baos.toString();
		return result;
	}
}
